package com.gs.wzweather.service;

import com.gs.wzweather.config.datasource.DatasourceKey;
import com.gs.wzweather.config.datasource.TargetDataSource;
import com.gs.wzweather.dao.OpenMasDao;
import com.gs.wzweather.dao.SmsThresholdDao;
import com.gs.wzweather.dao.StatisticsDao;
import com.gs.wzweather.dao.SurHorDao;
import com.gs.wzweather.entity.Site;
import com.gs.wzweather.entity.SmsThreshold;
import com.gs.wzweather.utils.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: Legolas
 * Date: 2017/11/23 0023
 */
@Service
@TargetDataSource(DatasourceKey.DB1)
public class SmsWarningService {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    SmsThresholdDao smsThresholdDao;

    @Autowired
    StatisticsDao statisticsDao;

    @Autowired
    SurHorDao surHorDao;

    @Autowired
    OpenMasDao openMasDao;

    @TargetDataSource(DatasourceKey.DB2)
    public  List<SmsThreshold>  getSmsThresholds(){
        return smsThresholdDao.querySmsThresholds();
    }

    public String getStatistics(String station,String element){
        String time = DateUtil.getTime();
        return statisticsDao.queryWeaByStation(station,time,element);
    }

    public String getSurHourMax(String station,String element,String pastH){
        String endTime = DateUtil.getTime();
        String beginTime = DateUtil.subTime(endTime, pastH);
        return surHorDao.queryMaxByStation(station,beginTime,endTime,element);
    }

    @TargetDataSource(DatasourceKey.DB3)
    public void sendMsg(String content){
        openMasDao.insertMsg(content);
    }

}
